<template>
  <qx-table :dbRowClick="rowDblClick" :option="tableOption" :remoteData="remoteData">
    <template v-slot:top>
      <qx-form v-model="searchForm" :option="tableOption" isSearch @submit="startSearch"></qx-form>
    </template>
    <template v-slot:menuLeftR>
      <q-icon color="warning" name="mdi-map-marker-question cursor-pointer cursor-hover" size="1.5rem">
        <q-tooltip class="q-pa-md" v-bind="$tooltipAttr">{{ $t('Misc.DblClickTips') }}</q-tooltip>
      </q-icon>
    </template>
  </qx-table>
  <q-modal v-model="modalVisible" :header="`${$t('Misc.SpecifyDetails')}`" :menuBtn="false" :persistent="false"
           width="620">
    <QInfo :columns="tableOption.column || []" :rowInfo="formInfo" cols="2"></QInfo>
  </q-modal>
</template>
<script setup>
import { i18n } from 'boot/i18n.js'
import { bindOrUnbind, yesOrNo } from 'src/enum/index.js'
import { computed, onMounted, ref } from 'vue'

const formInfo = ref({})
const searchForm = ref({})
const modalVisible = ref(false)
const remoteData = ref({ dicUrl: '/yfagv/api/bindStorageContainerLog/list' })
const tableOption = computed(() => {
  return {
    span: 22, export: true, labelWidth: 100, headerWidth: 60, searchSpan: 4, searchLabelWidth: 60,
    column: [{
      label: `${i18n.t('CarrierCore.ContainerType')}`, field: 'containerTypeCode', minWidth: 100, required: true
    }, {
      label: `${i18n.t('CarrierCore.ContainerCode')}`, field: 'containerCode', minWidth: 100
    }, {
      label: `${i18n.t('CarrierCore.RackCode')}`, field: 'shelvesCode', minWidth: 100, search: false
    }, {
      label: `${i18n.t('CarrierCore.SlotCode')}`, field: 'storageCode', minWidth: 100, required: true
    }, {
      label: `${i18n.t('TaskCore.RelatedTaskCode')}`, field: 'taskCode', minWidth: 100, search: false
    }, {
      label: `${i18n.t('LogCore.OperType')}`, field: 'operType', type: 'select', useTag: true,
      options: bindOrUnbind.value, minWidth: 100
    }, {
      label: `${i18n.t('Misc.IsManual')}`, field: 'isManual', type: 'select', options: yesOrNo.value, useTag: true,
      minWidth: 100, display: false, search: false, hide: true
    }, {
      label: `${i18n.t('LogCore.RequestCode')}`, field: 'reqCode', minWidth: 100, display: false,
      search: false, hide: true
    }, {
      label: `${i18n.t('LogCore.RequestTime')}`, field: 'reqTime', minWidth: 100, display: false, search: false
    }, {
      label: `${i18n.t('CreationTime')}`, field: 'createdTime', type: 'daterange', minWidth: 90,
      display: false
    }, {
      label: `${i18n.t('Remarks')}`, field: 'remark', minWidth: 100, search: false, display: false
    }]
  }
})

const rowDblClick = row => {
  formInfo.value = row
  modalVisible.value = true
}
const formatSearchForm = () => {
  const params = { ...searchForm.value }
  if (searchForm.value.createdTime?.from) {
    params.createdStartTime = params.createdTime?.from
    params.createdEndTime = params.createdTime?.to
    delete params.createdTime
  }
  return { ...params }
}
const startSearch = (_, done) => {
  remoteData.value.params = formatSearchForm()
  remoteData.value.clearSelected = true
  if (done) done()
}
onMounted(startSearch)
</script>